import parse from '@dfeidao/atom-web/dt/parse';
import get from '@dfeidao/atom-web/global/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import hide from '@dfeidao/atom-web/ui/hide';
import { productid } from '../../atom/config';
// 转换时间戳格式
export default async function a006(fd: IFeidaoAiBrowserComponent) {
	// 会议名称
	const meeting_name = fd.data.node.querySelector<HTMLInputElement>('[data-id="meeting_name"]').value;
	// 会议主题
	const conference_theme = fd.data.node.querySelector<HTMLInputElement>('[data-id="conference_theme"]').value;
	// 会议地点
	const meeting_address = fd.data.node.querySelector<HTMLInputElement>('[data-id="meeting_address"]').value;
	// 会议主持人
	const meeting_host = get('staff_name');
	// 会议主持人编号
	const meeting_host_no = get('staff_no');
	// 发起人编号
	const sponso_no = get('staff_no');
	// 发起人
	const sponsor = get('staff_name');
	// 当前时间
	const now_date = new Date().getTime(); // 1551167783406

	// 开始时间
	const start_time1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="start_time"]').value;
	const start_time = parse(start_time1);
	if (start_time < now_date) {
		alert('上班时间必须大于当前服务器时间');
		return;
	}
	// 结束时间


	// const new_date = format(now_date, 2);
	const finish_time1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="finish_time"]').value;
	const finish_time = parse(finish_time1);
	// 人员编号pub_user_no
	const arr1 = get('d');
	const arr2 = get('arr1');
	console.log(arr1);
	if (arr1 <= 0 || arr2 <= 0) {
		alert('请选择参会人员');
		return;
	}
	const pub_user_no = fd.data.node.querySelector<HTMLInputElement>('[data-id="i"]').getAttribute("data-no");
	// 人员名称pub_user_name
	const pub_user_name = fd.data.node.querySelector<HTMLInputElement>('[data-id="i"]').getAttribute("data-name");

	// 人员工号cabinet_staff_no
	// const dt = await nodejs<Array<{ cabinet_staff_no: string; department_no: string, deptname: string }>>('meeting-management/zj-000004/s002', {
	// 	staff_no: pub_user_no
	// });
	// console.log(dt);
	// const cabinet_staff_no = dt[0].cabinet_staff_no;
	// // 部门编号department_no
	// const department_no = dt[0].department_no;
	// // 部门名称dept_name
	// const dept_name = dt[0].deptname;
	// 消息类型编号 消息类型名称
	const dt1 = await nodejs<{ dt1: Array<{ msg_type_no: string; msg_type_name: string }> }>('meeting-management/zj-000004/s003', {});
	// console.log('dt1', dt1.dt1[0].msg_type_no);
	// 消息类型编号
	const msg_type_no = dt1.dt1[0].msg_type_no;
	// 消息模板
	const dt2 = await nodejs<{ dt2: Array<{ msg_templ_title: string; msg_templ_cont: string, msgtemplid: string }> }>('meeting-management/zj-000004/s004', {
		msg_type_no
	});
	// 消息类型名称
	const msg_type_name = dt1.dt1[0].msg_type_name;
	// 模板ID
	const msgtemplid = dt2.dt2[0].msgtemplid;
	// 消息标题
	const msg_title = dt2.dt2[0].msg_templ_title;
	// 消息内容
	const msg_cont = dt2.dt2[0].msg_templ_cont;
	// “发送人编号 sender_no”系统参数“员工编号 staff_no”
	const sender_no = get('staff_no');
	// “发送人姓名 sender_name”系统参数“员工名称 staff_name”
	const sender = get('staff_name');
	// “发送时间 send_time”当前服务器时间
	const send_time = finish_time;
	const res = await nodejs<{ code: 0 | 1; result: string }>('meeting-management/zj-000004/s001', {
		filter: {
			productid,
			meeting_name,
			conference_theme,
			meeting_address,
			meeting_host,
			meeting_host_no,
			sponso_no,
			sponsor,
			start_time,
			finish_time
		},
		filter1: {
			productid,
			pub_user_no,
			pub_user_name
			// cabinet_staff_no,
			// department_no,
			// dept_name
		},
		filter2: {
			productid,
			msg_type_no,
			msg_type_name,
			msgtemplid,
			msg_title,
			msg_cont,
			sender_no,
			sender,
			send_time
		},
		filter3: {
			productid,
			receiver_no: get('staff_no'),
			receiver: get('staff_name')
		}, filter4: {
			productid
		}
	});
	if (res.code === 1) {
		alert('添加成功');
		hide(fd.data.node);
		fire('zj-000001', 'a001');
		fire('zj-000001', 'a005');
	} else {
		alert('添加失败');
	}
}
